package com.work.straighttalk.presenter;

import android.util.Log;

import com.hyphenate.chat.EMCallStateChangeListener;
import com.work.straighttalk.model.VoiceCallMImpl;
import com.work.straighttalk.model.i.OnVoiceCallListener;
import com.work.straighttalk.model.i.VoiceCallMI;
import com.work.straighttalk.presenter.i.VoiceCallPI;
import com.work.straighttalk.ui.i.VoiceCallVI;

/**
 * Created by dllo on 16/3/11.
 */
public class VoiceCallPImpl implements VoiceCallPI, OnVoiceCallListener {
    private VoiceCallVI voiceCallVI;
    private VoiceCallMI voiceCallMI;

    public VoiceCallPImpl(VoiceCallVI voiceCallVI) {
        this.voiceCallVI = voiceCallVI;
        this.voiceCallMI = new VoiceCallMImpl();
    }

    @Override
    public void Call(String username, boolean isInComingCall) {
        Log.d("VoiceCallPImpl", username);
        Log.d("VoiceCallPImpl", "isInComingCall:" + isInComingCall);
        voiceCallMI.isCall(username, isInComingCall, this);
    }

    @Override
    public void setConversation() {
        Log.d("VoiceCallPImpl", "asdbsiunbnb");
        voiceCallMI.conversation(this);
    }

    @Override
    public void onDestroy() {
        voiceCallVI = null;

    }

    //打电话
    @Override
    public void callPhone() {
        Log.d("VoiceCallPImpl", "apsbnsijgnsdkgjn");
        if (voiceCallVI != null) {
            voiceCallVI.call();
        }

    }

    //接电话
    @Override
    public void mComingCall() {
        Log.d("VoiceCallPImpl", "apsbnsijgnsdkgjn2");
        if (voiceCallVI != null) {
            voiceCallVI.comingCall();
        }
    }

    //正在连接对方
    @Override
    public void mCinnecting() {
        Log.d("VoiceCallPImpl", "apsbnsijgnsdkgjn3");
        if (voiceCallVI != null) {
            voiceCallVI.cinnecting();
        }

    }

    //双方已经建立连接
    @Override
    public void mConnected() {
        Log.d("VoiceCallPImpl", "apsbnsijgnsdkgjn4");
        if (voiceCallVI != null) {
            voiceCallVI.connected();
        }

    }

    //电话接通
    @Override
    public void mAcceptend() {
        Log.d("VoiceCallPImpl", "apsbnsijgnsdkgjn5");
        if (voiceCallVI != null) {
            voiceCallVI.acceptend();
        }

    }

    //电话挂了
    @Override
    public void mDisconnnected( EMCallStateChangeListener.CallError callError) {
        Log.d("VoiceCallPImpl", "apsbnsijgnsdkgjn6");
        if (voiceCallVI != null) {
            voiceCallVI.disconnnected(callError);
        }
    }


}
